package edu.ccut.saturn.component.impl;

import edu.ccut.saturn.component.IMenuInfo;
import edu.ccut.saturn.component.IMuneItemInfo;

public class SaturnMenuItemInfo implements IMuneItemInfo {

	private String label;

	private String path;

	private String id;

	private String order;

	private String parentId;

	private IMenuInfo menuInfo;

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public SaturnMenuItemInfo(String label, String path, String id,
			String order, String parentId, IMenuInfo menuInfo) {

		this.label = label;
		this.path = path;
		this.id = id;
		this.order = order;
		this.parentId = parentId;
		this.menuInfo = menuInfo;
	}

	public SaturnMenuItemInfo(IMuneItemInfo info) {
		this(info.getLabel(), info.getPath(), info.getId(), info.getOrder(),
				info.getParentId(), info.getMenuInfo());
	}

	public String getLabel() {
		return this.label;
	}

	public String getPath() {
		return this.path;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getId() {
		return this.id;
	}

	public String getOrder() {
		return this.order;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	public int compareTo(IMuneItemInfo menuItemInfo) {

		if (this.order == null || "".equals(this.order)) {
			return -1;

		} else {
			int value = 0;
			int comparedValue = 0;

			try {
				value = Integer.parseInt(this.order.trim());
				comparedValue = Integer
						.parseInt(menuItemInfo.getOrder().trim());

			} catch (NumberFormatException e) {
				return 1;
			}

			if (value == comparedValue) {
				return 0;
			}
			return value > comparedValue ? 1 : -1;
		}
	}

	public IMenuInfo getMenuInfo() {
		return menuInfo;
	}

	public void setMenuInfo(IMenuInfo menuInfo) {
		this.menuInfo = menuInfo;
	}
}
